<div class="app-content-body ">
    <div class="bg-light lter b-b wrapper-md hidden-print">
      <h1 class="m-n font-thin h3">项目分类</h1>
    </div>

    <div class="form_title">
      <div class="my_hd edit-type">编辑</div>
      <div class="crud-container crud-reset">
        <form id="form-container">
          <div class="row">
            <div class="col-sm-12">
              <div id="form"></div>
            </div>
          </div> 
          <div class="row">
            <div class="col-sm-12 text-right" style="margin-top: 15px;">
                <div id="cancel"></div>
                <div id="save"></div>
            </div>
          </div>
        </form>
      </div>
    </div>
</div>
<script type="text/javascript">
$(function (){
    $("#content").one("route.loaded", function(e, context) {
	      var id=context.params.id ,
	      	  memberStore = API('project-category/'+ id);
	      	  
	      var formItems = [{
		        dataField: "name",
		        label: {text: '分类名称'},
		        validationRules: [{
		            type: "required",
		            message:( "请输入分类名称")
		        }]
	        }]
	      $.get(memberStore).then(function(msg){
	      	  if(msg.data.url){
	      	  	 $('#form-container').prepend("<div class='editImg'><img src='"+msg.data.url+"' /></div>");
	      	  }
		   	  form =  $("#form").dxForm({
		   	  	   formData:msg.data,
			       showColonAfterLabel: true,
			       showValidationSummary: false,
			       validationGroup: "crud",
			       items: formItems
		      }).dxForm("instance");
	  	  },'json');
	  	  
	  	 $("#form-container").on("submit", function(e) {
	        var data = form.option('formData'),
	        	udata = {name: data.name};
			$.ajax({
				url:memberStore,
				type:'PUT',
				data:udata,
				success:function(){
					DevExpress.ui.notify({
				            message: "已完成",
				    }, "success", 1000);
				    context.redirect("#/project-classification");
				}
			})
	        return false;
	      });
			
	      $("#cancel").dxButton({
	          text: "返回",
	          type: "normal",
	          onClick:function(){
	             context.redirect("#/project-classification");
	          }
	      });
	      $("#save").dxButton({
	        text: "保存",
	        type: "success",
	        useSubmitBehavior: true,
	        validationGroup: "crud"
	      });
    });
});
</script>